home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / ProjectDrag 1.1b4 / Sources / ProjectDrag Sources / TasksAndErrors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  4.5 KB  |  194 lines  |  [TEXT/MPS ]

  1. /* TasksAndErrors.h: Task and error notification routines for ProjectDrag
  2.  *
  3.  * A set of applets for drag and drop source control by Tim Maroney.
  4.  * See develop, issue 23 for details.
  5.  *
  6.  * Built on DropShell by Leonard Rosenthol, Stephan Somogyi, and Marshall Clow,
  7.  * and using the MoreFiles utilities by Jim Luther.
  8.  *
  9.  * This software is free, but don't modify and redistribute it without
  10.  * changing the status window to indicate your name and your changes!
  11.  */
  12.  
  13. #include <Dialogs.h>
  14. #include <Errors.h>
  15. #include <LowMem.h>
  16. #include <ToolUtils.h>
  17.  
  18. #include "TasksAndErrors.h"
  19. #include "DSGlobals.h"
  20. #include "PDUtilities.h"
  21.  
  22.  
  23. #define    kResTextAlertID    207
  24.  
  25. #define kStatusWindow 210
  26. #define kStatusInfo 1
  27. #define kStatusText 3
  28.  
  29.  
  30. typedef struct TaskStackEntry
  31. {
  32.     struct TaskStackEntry *fNext;
  33.     Str255 fMessage;
  34. } TaskStackEntry;
  35.  
  36.  
  37. static DialogPtr pStatusWindow;
  38. static OSErr pTaskError;
  39. static Str255 pTaskErrorString;
  40. static Boolean pHaveErrorNumber = false;
  41. static Boolean pHaveErrorString = false;
  42. static TaskStackEntry *pTaskStack = NULL;
  43.  
  44.  
  45. static void ResTextErrorAlert(short strListID, short strIndex, OSErr callerErr,
  46.                                StringPtr param1, StringPtr param2,
  47.                                StringPtr param3, StringPtr param4);
  48.  
  49.  
  50. static void InstallStatusWindow(void) 
  51. {
  52.     if (pStatusWindow == NULL)
  53.     {
  54.         short type;
  55.         Handle h;
  56.         Rect r;
  57.         Str255 s;
  58.                 
  59.         pStatusWindow = GetNewDialog(kStatusWindow, NULL, (WindowPtr)-1);
  60.         GetDItem(pStatusWindow, kStatusInfo, &type, &h, &r);
  61.         ReplaceInIndString(s, kProjectDragStrings, kTimsByline, LMGetCurApName(),
  62.                             NULL, NULL, NULL);
  63.         SetIText(h, s);
  64.         ShowWindow(pStatusWindow);
  65.         DrawDialog(pStatusWindow);
  66.     }
  67. }
  68.  
  69.  
  70. void SetStatusMessage(StringPtr message)
  71. {
  72.     short type;
  73.     Handle h;
  74.     Rect r;
  75.     Str255 s;
  76.     unsigned char nullString[1];
  77.     
  78.     if (pStatusWindow == NULL)
  79.         InstallStatusWindow();
  80.  
  81.     GetDItem(pStatusWindow, kStatusText, &type, &h, &r);
  82.     GetIText(h, s);
  83.     if (message == NULL)
  84.     {
  85.         nullString[0] = 0;
  86.         message = nullString;
  87.     }
  88.     if (!EqualString(message, s, true, true))
  89.         SetIText(h, message);
  90. }
  91.  
  92.  
  93. void TaskStart(short strListID, short strIndex, StringPtr param1, StringPtr param2,
  94.                 StringPtr param3, StringPtr param4)
  95. {
  96.     Str255 message;
  97.     TaskStackEntry *theEntry;
  98.     
  99.     ReplaceInIndString(message, strListID, strIndex, param1, param2, param3, param4);    
  100.     SetStatusMessage(message);
  101.     
  102.     /* push the task string onto the task stack */
  103.     theEntry = (TaskStackEntry*)NewPtr(sizeof(TaskStackEntry));
  104.     /* XXX uh-oh if there's no memory */
  105.     BlockMoveData(message, theEntry->fMessage, message[0] + 1);
  106.     theEntry->fNext = pTaskStack;
  107.     pTaskStack = theEntry;
  108. }
  109.  
  110.  
  111. void TaskDone(void)
  112. {
  113.     /* pop the task from the task stack */
  114.     TaskStackEntry *theEntry = pTaskStack;
  115.     pTaskStack = pTaskStack->fNext;
  116.     DisposePtr((Ptr)theEntry);
  117.     
  118.     if (pTaskStack != NULL)
  119.     {
  120.         SetStatusMessage(pTaskStack->fMessage);
  121.     }
  122.     else if (!gDone)
  123.     {
  124.         /* put nothing in the status window */
  125.         SetStatusMessage(NULL);
  126.     }
  127. }
  128.  
  129.  
  130. void PopAllTasks(void)
  131. {
  132.     /* if there was an error, show the alert */
  133.     if (pHaveErrorNumber)
  134.     {
  135.         if (pTaskError != userCanceledErr)
  136.             ResTextErrorAlert(kProjectDragStrings, kAnErrorOccured, pTaskError,
  137.                               pTaskStack->fMessage, NULL, NULL, NULL);
  138.     }
  139.     else if (pHaveErrorString)
  140.     {
  141.         ResTextErrorAlert(kProjectDragStrings, kAnErrorOccured, pTaskError,
  142.                             pTaskStack->fMessage, pTaskErrorString, NULL, NULL);
  143.     }
  144.     pHaveErrorNumber = pHaveErrorString = false;
  145.     
  146.     /* delete the task stack */
  147.     while (pTaskStack)
  148.     {
  149.         TaskStackEntry *theEntry = pTaskStack;
  150.         pTaskStack = pTaskStack->fNext;
  151.         DisposePtr((Ptr)theEntry);
  152.     }
  153.     
  154.     /* put nothing in the status window */
  155.     SetStatusMessage(NULL);
  156. }
  157.  
  158.  
  159. OSErr RaiseErrorNumber(OSErr err)
  160. {
  161.     /* mark the error for PopAllTasks to show */
  162.     pHaveErrorNumber = true;
  163.     pTaskError = err;
  164.     return err;
  165. }
  166.  
  167.  
  168. void RaiseErrorString(short strListID, short strIndex,
  169.                        StringPtr param1, StringPtr param2,
  170.                        StringPtr param3, StringPtr param4)
  171. {
  172.     /* mark the error for PopAllTasks to show */
  173.     pHaveErrorString = true;
  174.     ReplaceInIndString(pTaskErrorString, strListID, strIndex,
  175.                        param1, param2, param3, param4);
  176. }
  177.  
  178.  
  179. void ResTextErrorAlert(short strListID, short strIndex, OSErr callerErr,
  180.                        StringPtr param1, StringPtr param2,
  181.                        StringPtr param3, StringPtr param4)
  182. {
  183.     Str255 message;
  184.     Str255 errorString;
  185.     
  186.     if (callerErr != noErr)
  187.         NumToString (callerErr, errorString);
  188.     else
  189.         errorString[0] = 0;
  190.     ReplaceInIndString(message, strListID, strIndex, param1, param2, param3, param4);    
  191.     ParamText(message, errorString, NULL, NULL);
  192.     (void) Alert ( kResTextAlertID, NULL );
  193. }
  194.